import Vue from 'vue'
import Router from 'vue-router'
import Home from "@/views/Home.vue";
import Category from "@/views/Category.vue";
import store from '@/store';

Vue.use(Router)

const router = new Router({
  mode: "history",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      name: "index",
      component: Home
    },
    {
      path: "/recomment",
      name: "recomment",
      component: Home
    },
    {
      path: "/category",
      name: "category",
      component: Category
    },
    {
      path: "/food",
      name: "food",
      component: Home
    },
    {
      path: "/catemenu",
      name: "catemenu",
      component: Home
    },
    {
      path: "/user",
      name: "user",
      component: Home
    },
    {
      path: "/comment",
      name: "comment",
      component: Home
    },
    {
      path: "/favorite",
      name: "favorite",
      component: Home
    }
  ]
});

router.beforeEach((to, from, next) => {
  next();
  // console.log(to);
  // 把 to.path 更新到 store 中
  store.commit("setRoutePath", to.path);
});

export default router;